package org.vaadinpa.data;

import java.util.Random;

import org.vaadinpa.Conf;

public class Coordinate {

	public int x;
	public int y;

	public Coordinate(int x, int y) {
		this.x = x;
		this.y = y;
	}

	@Override
	public boolean equals(Object o) {
		if (this == o) {
			return true;
		}
		if (o == null || !this.getClass().equals(o.getClass())) {
			return false;
		}

		Coordinate other = (Coordinate) o;
		return x == other.x && y == other.y;
	}

	@Override
	public int hashCode() {
		return x * 93939 + y;
	}

	public int distanceTo(Coordinate other) {
		return (int) Math.sqrt(Math.abs(x - other.x) ^ 2 + Math.abs(y - other.y) ^ 2);
	}

	public static Coordinate getRandom() {
		Random r = new Random();
		return new Coordinate(r.nextInt(Conf.UNIVERSE_SIZE), r.nextInt(Conf.UNIVERSE_SIZE));
	}

	@Override
	public String toString() {
		return "X:" + x + " Y:" + y;
	}
}
